#include "NWindow.h"

NWindow::NWindow()
{
    window =  newwin(LINES, COLS, 0, 0);
    x = 0;
    y = 0;
    width = COLS;
    height = LINES;
}

NWindow::NWindow(int startWidth, int startHeight, int startx, int starty, bool border)
{
    x = startx;
    y = starty;
    width = startWidth;
    height = startHeight;
    window = newwin(height, width, y, x);
    
    visible = false;

    if (border)
    {
        box(window, 0, 0);
        border = true;
    }
    else
        border = false;
}

void NWindow::setHeight(int newHeight)
{
    height = newHeight;
}

void NWindow::setWidth(int newWidth)
{
    width = newWidth;
}

void NWindow::hide()
{
    if (visible)
    {
        clear();
        visible = false;
    }
}

void NWindow::show()
{
    if (! visible)
    {
	    wrefresh(window);
	    visible = true;
    }
}

void NWindow::clear()
{
    werase(window);
    refresh();
}

void NWindow::printChar(int x, int y, chtype newChar)
{
    mvwaddch(window, y, x, newChar);
    refresh();
} 

void NWindow::printChar(Point point, chtype newChar)
{
    printChar(point.x, point.y, newChar);
}

void NWindow::printChar(chtype newChar)
{
    waddch(window, newChar);
	refresh();
}

void NWindow::printString(int x, int y, string newString)
{
    mvwprintw(window, y, x, newString.c_str());
    refresh();
}

void NWindow::printString(Point point, string newString)
{
    printString(point.x, point.y, newString.c_str());
}

void NWindow::printString(const char *newString)
{
    wprintw(window, newString);
    refresh();
}

void NWindow::refresh()
{
    if (visible)
        wrefresh(window);
}

NWindow::~NWindow()
{
    delwin(window);
}
